Ext.onReady(function ()
{
	function submitForm()
	{
		if (deleteEnvironmentForm.getForm().isValid())
		{
			deleteEnvironmentForm.getForm().submit(
			{
				url : basePath + 'room/deleteEnvironment',
				method : 'POST',
				waitMsg : '正在删除，请稍候...',
				waitTitle : '删除中',
				timeout : 300000,
				params : deleteEnvironmentForm.getValues(),
				success : function (deleteEnvironmentForm, action)
				{
					var isSuc = action.result.success;
					if (isSuc)
					{
						EnvironmentNameBox.store.removeAll();
						EnvironmentNameBox.store.reload();
						EnvironmentNameBox.setValue('');
						Ext.Msg.alert('删除成功！', '已经成功删除！');
					}
					else
					{
						var res = action.result.res;
						Ext.Msg.alert('删除失败', res);
					}
				},
				failure : function (addCourseForm, action)
				{
					var res = action.result.res;
					Ext.Msg.alert('删除失败', res);
				}
			}
			);
		}
	}

	//获得数据store
	var EnvironmentData = Ext.create('Ext.data.Store',
		{
			model : 'EnvironmentModel',
			proxy :
			{
				type : 'ajax',
				url : basePath + 'room/getEnvironmentList',
				reader :
				{
					type : 'json',
					root : 'root'
				}
			},
			autoLoad : true
		}
		);

	//数据填充入combobox
	var EnvironmentNameBox = Ext.create('Ext.form.ComboBox',
		{
			fieldLabel : '环境:',
			emptyText : '请选择要删除的环境',
			labelWidth : 100,
			width : 400,
			labelAlign : "right",
			store : EnvironmentData,
			queryMode : 'local',
			editable : false,
			name : 'environment_id',
			hiddenName : 'environment_id',
			displayField : 'name',
			valueField : 'environment_id',
			blankText : '不能为空',
			allowBlank : false
		}
		);

	var tmp = Ext.getCmp('deleteEnvironmentForm');
	if (tmp != null)
		tmp.destroy();
	var deleteEnvironmentForm = Ext.create("Ext.form.FormPanel",
		{
			title : '删除环境',
			frame : false,
			defaultType : 'textfield',
			renderTo : 'showDeleteEnvironmentDiv',
			defaults :
			{
				anchor : '100%',
				labelWidth : 100,
				labelAlign : "right"
			},
			items : [
				EnvironmentNameBox
			],
			buttons : [
				{
					text : '确定',
					handler : function ()
					{
						submitForm();
					}
				}
			]
		}
		);
}
);
